﻿

-- 人均工时考勤表
create procedure [dbo].[Report_Rjgs]
@qybmm varchar(100) = null,
@begindate datetime = null,
@enddate datetime = null
as
select aa.xm,aa.sfzh,isnull(cqts,0) cqts,isnull(zgs,0)/3600 zgs,isnull(zgs,0)/3600/isnull(cqts,1) rjgs
from
(
select xm,sfzh from vRyBzInfo
where @qybmm is null or isnull(bzmc,'未知')=@qybmm
) aa
left join
(
select xm,sfzh,count(1) cqts,sum(ljgs) zgs
from Compute_Rygs
where (@qybmm is null or qybmm=@qybmm) and (@begindate is null or kqsj>=@begindate)
and (@enddate is null or kqsj<=@enddate)
group by xm,sfzh
) bb on(aa.sfzh=bb.sfzh)